package com.sirun.cn.fca.service;

import com.tencent.tac.crash.TACCrashService;

/**
 * @author vinsonhuang
 * @date 2018/8/30
 */
public class TXCrashService implements Thread.UncaughtExceptionHandler {

    private static final TXCrashService INSTANCE = new TXCrashService();

    private static Thread.UncaughtExceptionHandler sDefaultHandler;

    private TXCrashService() {
    }

    public static void init() {
        sDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(INSTANCE);
    }

    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        if (null != ex) {
            TACCrashService.getInstance().postCatchedException(ex);
            sDefaultHandler.uncaughtException(thread, ex);
        }
    }
}
